Skip to content

Fix columns order in aggregation queries #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 1, 2025

Conversation

WaVEV
Copy link
Collaborator

@WaVEV WaVEV commented Dec 21, 2024

Adaptations for django/django@65ad4ad.

# Reference to a column.
elif isinstance(expression, int):
expression = columns[expression]
selected.append(project_field(expression))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there another option where expression isn't str or int and expression is used on the next line as-is?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 having checked set_values and the method check_alias the fields must be tuples of string. So, I can conclude that everything there is string and the integer are introduced here

@@ -395,20 +395,10 @@ def build_query(self, columns=None):
return query

def get_columns(self):
"""
Return a tuple of (name, expression) with the columns and annotations
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the docstring already outdated? You didn't think a new one would be useful?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so; the return value remains unchanged. I decided not to modify it because doing so would break other functions, such as subquery.

Long story short: the selection forces changes to the names of some returning columns. This behavior makes it difficult to track when a column's name changes. While I don't know if this was caused by collisions, there's no test to confirm it, and I can't imagine one either.

That said, as long as _make_result returns tuples, we can manage our own names (e.g., __annotation#), and everything should work fine.

So, the docstring is fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know why I deleted it. 😬

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restored without with period!? 😉

Please check CI failures. I invited you as a collaborator to my fork so hopefully CI will run automatically in the future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, is everything broken it worked in my computer. 😬 let's fix the things.

@timgraham
Copy link
Owner

Does it make sense to send "get_columns as a cached property' to main so the branches don't diverge on that?

@WaVEV
Copy link
Collaborator Author

WaVEV commented Jan 1, 2025 via email

@timgraham timgraham force-pushed the fix-aggregation-queries branch from 4716c5e to 67d9d3f Compare January 1, 2025 19:41
@timgraham timgraham merged commit 67d9d3f into timgraham:django52 Jan 1, 2025
7 checks passed
@WaVEV WaVEV deleted the fix-aggregation-queries branch January 2, 2025 02:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants